package com.doit.demo03;

@SuppressWarnings("all")
public class test03_Thread {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    try {
                        Thread.sleep(200);//父类方法不抛异常,子类就不能抛
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+" "+i);
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+" "+i);
                }
            }
        });
        t1.setDaemon(true);//将t1设置为守护线程 意思就是t2执行完之后,就结束了,不管t1执行到哪一步直接结束
                            //将t1设置为守护线程,意思就是t2执行完之后,就结束了,不管t1执行到哪一步直接结束
                            //将t1设置为守护线程,意思就是t2执行完之后,就结束了.不管t1执行到哪一步直接结束
        t1.start();
        t2.start();//不设置的都叫用户线程
    }
}
